package com.alterzhang.heartbeat;


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

public class MyServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {


            IdleStateEvent event = (IdleStateEvent) evt;

            String eventStatus = null;

            switch (event.state()) {
                case READER_IDLE:
                    eventStatus = "读空闲";
                    break;
                case WRITER_IDLE:
                    eventStatus = "写空闲";
                    break;
                case ALL_IDLE:
                    eventStatus = "读写空闲";
                    break;
            }
            System.out.println(ctx.channel().remoteAddress() + ":" + eventStatus);
        }

        ctx.channel().close();
    }
}
